// pages/scaner/index.js 
import Toast from '@vant/weapp/toast/toast';
import {
  get,
  post,
  put
} from '../../../request/index'
const AUTH = require('../../../utils/auth')
const {
  typeJson
} = require('../../../utils/typejson')
const userInfo = JSON.parse(wx.getStorageSync('prolist'))

Page({

  /**
   * 页面的初始数据
   */
  data: {
    dataList: [],
    userId: '',
    flowNo: null,
    dialogShow: false,
    parmes: {
      userId: null,
      flowNo: null,
      isOk: 1,
      remark: '',
    }
  },
  change(e) {
    console.log(e);
  },
  submit(e) {
    let data = e.currentTarget.dataset.item
    let type = e.currentTarget.dataset.type
    console.log(data, type);
    this.setData({
      parmes: {
        userId: userInfo.userId,
        flowNo: data.flowNo,
        isOk: type,
        remark: '',
        id:data.id
      },
      dialogShow: true
    })
  },
  // 确认提交
  dialogConfirm() {
    put('/app/emergproject', this.data.parmes).then(res => {
      if (res.code === 200) {
        wx.showToast({
          title: '发布成功',
          duration: 3000,
          icon: 'none',
          mask: true
        })
        this.getList()
        this.dialogClose()
      }
    }).catch(err => {
      console.log(err);
    })
  },
  dialogClose() {
    this.selectComponent("#upload").clearImg();
    this.setData({
      dialogShow: false,
      parmes: {
        userId: null,
        flowNo: null,
        isOk: 1,
        remark: '',
        id:''
      }
    })
  },
  // 签名
  canvasChang(e) {
    let value = 'parmes.remark'
    console.log(e);
    this.setData({
      [value]: e.detail
    })
  },
  // 签到
  sign(e) {
    let data = e.currentTarget.dataset.item
    let parmes = {
      flowNo: data.flowNo,
      userId: userInfo.userId
    }
    // {flowNo}/{userId
    get(`/app/emerg/signCode/${data.flowNo}/${userInfo.userId}`).then(res => {
      if (res.code === 200) {
        wx.showToast({
          title: '签到成功',
          duration: 3000,
          icon: 'none',
          mask: true
        })
        this.getList()
      }


    }).catch(err => {

    })


  },
  // 获取数据
  async getList() {
    let parmes = {
      userId: userInfo.userId,
      flowNo: this.data.flowNo,
      //isOk: 0
    }
    let res = await post(`/app/emergproject/list`, parmes)
    this.setData({
      dataList: res.rows
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      userId: userInfo.userId,
      flowNo: options.flowNo
    })
    this.getList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})